package com.tanhua.server.controller;

import com.tanhua.model.vo.PageResult;
import com.tanhua.server.service.CommentsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/comments")
public class CommentsController {
    @Autowired
    private CommentsService commentsService;

    /**
     * 添加评论
     * @param map
     * @return
     */
    @PostMapping
    public ResponseEntity comment(@RequestBody Map map){

        String movementId = (String) map.get("movementId");
        String comment = (String) map.get("comment");
        commentsService.comment(movementId,comment);
        return ResponseEntity.ok(null);
    }


    /**
     * 查询评论
     * @param page
     * @param pagesize
     * @param movementId
     * @return
     */
    @GetMapping
    public ResponseEntity commentIn(@RequestParam(defaultValue = "1") Integer page,
                                    @RequestParam(defaultValue = "10") Integer pagesize,
                                    String movementId){
        PageResult pr=commentsService.findComments(movementId,page,pagesize);
        return ResponseEntity.ok(pr);
    }

    //评论点赞
    @GetMapping("/{id}/like")
    public ResponseEntity commentLike(@PathVariable String id){
        Integer count = commentsService.commentLike(id);
        return ResponseEntity.ok(count);
    }
    //评论取消赞
    @GetMapping("/{id}/dislike")
    public ResponseEntity commentDislike(@PathVariable String id){
        Integer count = commentsService.commentDislike(id);
        return ResponseEntity.ok(count);
    }




}
